package com.example.cloudAlibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hanjc
 */
@RestController
@RequestMapping("/service")
public class Controller {

    @Value("${server.port}")
    private String serverPort;

    @RequestMapping("/testA")
    public String testA() {

        int i = 1 / 0;
        return "testA success\n" + serverPort;
    }

    @RequestMapping("/testB")
    public String testB() {

        return "testB success\n" + serverPort;
    }

    @GetMapping("/testHotkey")
    @SentinelResource(value = "testHotkey", blockHandler = "dealTestHotkey")
    public String testHotkey(
            @RequestParam(value = "p1", required = false) String p1,
            @RequestParam(value = "p2", required = false) String p2
    ) {

        return "hotkey test succeed";
    }

    public String dealTestHotkey(String p1, String p2, BlockException exception) {

        return "failed\no(TヘTo)";
    }

}
